package com.blobfish.fiction.common.base.controller;

import com.blobfish.fiction.common.base.model.QmResult;
import com.jfinal.core.Controller;

/**
 * 基础controller
 */
public abstract class BaseController<T, DTO> extends Controller {
    public BaseController() {
    }

    /**
     * 返回成功
     * @param needRefresh 是否需要刷新
     * @return
     */
    public QmResult<DTO> renderSuccess(String message, boolean needRefresh) {
        QmResult<DTO> result = new QmResult<>();
        result.setCode(200);
        result.setMsg(message);
        result.setNeedRefresh(needRefresh);
        return result;
    }

    /**
     * 返回失败
     * @param needRefresh 是否需要刷新
     * @return
     */
    public QmResult<DTO> renderFail(String message, boolean needRefresh) {
        QmResult<DTO> result = new QmResult<>();
        result.setCode(500);
        result.setMsg(message);
        result.setNeedRefresh(needRefresh);
        return result;
    }
}
